<template>
	<body-wrap isFlex>
		<view class="topBox">
			<view class="imgbox">
				<cm-image v-if="detail._id" :src="detail.selfAvatar || detail.avatar"/>
			</view>
			<view class="top-con">
				<view class="name">
					{{detail.name || detail.nickname}}
					<text class="bzhi">专家</text>
					<view class="guanzhu" v-if="follows.length>0">已关注</view>
					<view class="guanzhu" v-else @click="addgz">关注</view>
				</view>
				<view class="intro">
					{{detail.company}} | {{detail.industry}} | {{detail.jobs}}
				</view>
				<text class="pfwf">服务人数：<text class="num">0</text>人，评分：<text class="num">5</text>分</text>
			</view>
		</view>
		<view class="detailCon">
			<view class="zjTab">
				<text class="item" :class="{'selected':active==1}" @click="setTab(1)">专家信息</text>
				<text class="item" :class="{'selected':active==2}" @click="setTab(2)">用户评价</text>
			</view>
			<view class="content">
				<info v-if="active==1" :detail="detail || {}"/>
				<comment v-else-if="active==2" :detail="detail || {}"/>
			</view>
		</view>
		<template #footer>
			<view class="ftBtnBox">
				<view class="ibtn">
					<view class="myBtn" @click="goOnline">在线咨询</view>
				</view>
				<view class="ibtn">
					<view class="myBtn" @click="openPop">约聊</view>
				</view>
			</view>
			<!-- <div class="ftBtnBox">
				<div class="myBtn" @click="save">保存</div>
			</div> -->
		</template>
		<uni-popup ref="popup">
			<view class="ylfs">
				<navigator class="yltype" url="/pages/preBook/index?type=1">一对一语言约聊</navigator>
				<navigator class="yltype" url="/pages/preBook/index?type=2">线下咨询预约</navigator>
			</view>
		</uni-popup>
	</body-wrap>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import bodyWrap from "@/components/bodyWrap/index.vue"
	import cmImage from "@/components/cmImage/index.vue"
	import info from "./components/info.vue"
	import comment from "./components/comment.vue"
	import {getUserInfo} from '@/api/base.js'
	import {getFollowList,addFollow} from "@/api/consult.js"
	import {toast} from "@/utils/common.js"
	export default defineComponent({
		components:{
			bodyWrap,
			cmImage,
			info,
			comment
		},
		props:{
		
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				userInfo:computed(()=>store.state.base.userInfo),
				active:1,
				tId:'', // 教师id
				detail:'',  // 教师详细信息
				follows:[]
			})
			
			onLoad(options=>{
				if(options && options.id){
					state.tId = options.id
				}
			})
			
			onMounted( async ()=>{
				const res = await getUserInfo(state.tId)
				if(res.code == 200){
					state.detail = res.data
				}
				getgzlist()
			})
			
			const getgzlist = ()=>{
				getFollowList({
					teacher:state.detail._id,
					user:state.userInfo._id
				}).then(res =>{
					state.follows = res.data.data || []
				})
			}
			
			const setTab = num=>{
				state.active = num
			}
			const openPop = ()=>{
				//proxy.$refs.popup.open('bottom')
				uni.navigateTo({
					url:`/pages/preBook/index?teacherId=${state.detail._id}`
				})
			}
			const addgz = async ()=>{
				addFollow({
					teacher:state.detail._id,
					user:state.userInfo._id
				}).then(res =>{
					if(res.code == 200){
						getgzlist()
						toast('关注成功')
					}else{
						toast(res.message || '关注失败')
					}
				})
			}
			const goOnline = ()=>{
				store.commit('base/set_selectTeacher',state.detail)
				uni.navigateTo({
					url:'/pages/question/add'
				})
			}
			
			return {
				...toRefs(state),
				setTab,
				openPop,
				addgz,
				goOnline
			}
		}
	})
</script>

<style lang="scss" scoped>
	.topBox{
		display: flex;
		margin: 0;
		padding:40rpx 20rpx 60rpx 20rpx;
		background: url(http://sunlight.ej12366.video/images/tbg.jpg) left top no-repeat;
		background-size: 101% auto;
		.imgbox{
			width: 140rpx;
			height: 140rpx;
			border-radius: 50%;
			overflow: hidden;
			flex-shrink: 0;
		}
		.top-con{
			padding: 0 0 0 20rpx;
			flex-shrink: 0;
			height: 0;
			line-height: normal;
			.name{
				display: flex;
				height: 50rpx;
				align-items: center;
				font-size: 34rpx;
				font-weight: bold;
				padding: 0;
				margin: -8rpx 0 0 0;
				color: #fff;
				.bzhi{
					display:flex;
					align-items: center;
					background-color: #ff1120;
					font-size: 26rpx;
					color: #fff;
					padding: 0 8rpx;
					border-radius: 5rpx;
					margin: 0 0 0 10rpx;
					height: 40rpx;
				}
				.guanzhu{
					font-size: 26rpx;
					color: #e3af2f;
					border: 1px solid #e3af2f;
					margin: 0 0 0 20rpx;
					padding: 5rpx 15rpx;
					border-radius: 5rpx;
				}
			}
			.intro{
				color: #999;
				font-size: 30rpx;
				height: 50rpx;
				line-height: 50rpx;
				width: 100%;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
				word-break: break-all;
				padding: 0;
			}
			.pfwf{
				color: #999;
				font-size: 30rpx;
				.num{
					font-weight: bold;
					color: #ff1120;
				}
			}
		}
	}
	.detailCon{
		background-color: #fff;
		//height: 800rpx;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		margin: -20rpx 0 0 0;
		.zjTab{
			display: flex;
			height: 90rpx;
			align-items: center;
			font-size: 34rpx;
			border-bottom: 1px solid #f3f3f3;
			.item{
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: center;
				position: relative;
				z-index: 10;
				height: 100%;
				&.selected{
					color: #e3af2f;
					&::after{
						content: '';
						position: absolute;
						z-index: 10;
						left: 0;
						bottom: 0;
						width: 100%;
						height: 1px;
						background-color: #e3af2f;
					}
				}
			}
		}
		.content{
			padding: 20rpx;
		}
	}
	.ftBtnBox{
		display: flex;
		padding: 20rpx 0;
		.ibtn{
			flex: 1;
			padding: 0 15rpx;
		}
	}
	.ylfs{
		background-color: #e3af2f;
		height: 200rpx;
		margin:0 30rpx 10rpx 30rpx;
		border-radius: 20rpx;
		.yltype{
			display: flex;
			align-items: center;
			height: 80rpx;
			padding: 0 30rpx;
			font-size: 30rpx;
			color: #fff;
		}
	}
</style>
